//
//  WZXFirstTableViewCell.m
//  WWLNetease
//
//  Created by dllo on 15/12/22.
//  Copyright © 2015年 Echo.Jobs. All rights reserved.
//

#import "WZXFirstTableViewCell.h"

@implementation WZXFirstTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createSubView];
    }
    return self;
}

- (void)createSubView {
    
//    // 图片
    self.imageV = [[UIImageView alloc] initWithFrame:CGRectMake(10 * SIZE, 10 * SIZE, 355 * SIZE, 170 * SIZE)];
    self.imageV.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:self.imageV];
//
    // 标题
    self.titleL = [[UILabel alloc] initWithFrame:CGRectMake(10 * SIZE, self.imageV.frame.size.height + 15 * SIZE, self.imageV.frame.size.width, 25 * SIZE)];
    self.titleL.font = [UIFont systemFontOfSize:18 * SIZE];
    [self.contentView addSubview:self.titleL];
//
//    
//    // 详情
    self.digestL = [[UILabel alloc] initWithFrame:CGRectMake(10, self.imageV.frame.size.height + self.titleL.frame.size.height + 10 * SIZE, self.titleL.frame.size.width, 50 * SIZE)];
    self.digestL.font = [UIFont systemFontOfSize:14 * SIZE];
    self.digestL.textColor = [UIColor colorWithWhite:0.620 alpha:1.000];
    self.digestL.numberOfLines = 0;
    [self.contentView addSubview:self.digestL];
    
//    // 跟贴
    self.replyF = [[UITextField alloc] initWithFrame:CGRectMake(300 * SIZE, 170 * SIZE, 70 * SIZE, 15 * SIZE)];
    // 设置文字的对齐方式
    self.replyF.textAlignment = NSTextAlignmentCenter;
    self.replyF.borderStyle = UITextBorderStyleRoundedRect;
    self.replyF.userInteractionEnabled = NO;
    self.replyF.textColor = [UIColor lightGrayColor];
    self.replyF.borderStyle = UITextBorderStyleRoundedRect;
    self.replyF.font = [UIFont systemFontOfSize:11 * SIZE];
    [self.contentView addSubview:self.replyF];
//
    //右上角new
    self.newsImageV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"subscription_topic_new@2x.png"]];
    self.newsImageV.frame = CGRectMake(316 * SIZE, 15 * SIZE, 44 * SIZE, 22 * SIZE);
    [self.contentView addSubview:self.newsImageV];
    
    //左下角角标
    self.numImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"todaynews_cell_tag@2x.png"]];
    self.numImageV.frame = CGRectMake(10 * SIZE, 160 * SIZE, 26 * SIZE, 20 * SIZE);
    [self.contentView addSubview:self.numImageV];
    
    //左下角角标数字
    self.numLabel = [[UILabel alloc] initWithFrame:CGRectMake(10 * SIZE, 160 * SIZE, 20 * SIZE, 20 * SIZE)];
    self.numLabel.textAlignment = NSTextAlignmentCenter;
    self.numLabel.font = [UIFont systemFontOfSize:14 * SIZE];
    self.numLabel.textColor = [UIColor whiteColor];
    self.numLabel.text = @"1";
    [self.contentView addSubview:self.numLabel];
    

}

-(void)setModel:(WZXButtonModel *)model
{
    _model = model;
    // 标题
    self.titleL.text = model.title;
    // 图片
    NSURL *url = [NSURL URLWithString:model.imgsrc];
    [self.imageV sd_setImageWithURL:url placeholderImage:nil];
    // 简介
    self.digestL.text = model.digest;
    // 跟贴
#pragma mark - 请求跟帖数
    CGFloat replayC = [self.model.replyCount floatValue];
    if (replayC > 0) {
        NSString *replayStr = [NSString stringWithFormat:@"%.0f跟帖", replayC];
        if (replayC >= 10000 ) {
            replayStr = [NSString stringWithFormat:@"%.1f万跟帖", replayC / 10000];
        }
        NSInteger lenth = replayStr.length;
        CGFloat w = (lenth + 2 * SIZE) * 8.0 * SIZE + 5 * SIZE;
        CGRect temp = self.replyF.frame;
        temp.size.width = w;
        self.replyF.frame = temp;
        self.replyF.center = CGPointMake(330 * SIZE, 250 * SIZE);
        self.replyF.text = replayStr;
        
    } else {
        
        self.replyF.borderStyle = UITextBorderStyleNone;
    }
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
